<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <!-- $Id: NCoverFAQ.html 1158 2007-09-27 13:30:53Z alan $ -->
        <title></title>
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <style> body { font-size: 10pt; font-family: Verdana; }
	p.title { font-size: 20pt; font-weight: bold; }
	.subtitle { color: maroon; }
	p.question { font-weight: bold; }
	pre { font-size: 10pt; font-family: Courier; }
	.usage { background-color: #F0F0F0; }
	.quote { background-color: #F0F0F0; margin-left: 36pt;}
	.method { color: maroon; font-size: 10pt; font-weight: bold; }
	.hdrcell { background-color: #DDEEFF; font-size: 10pt; }
	.datacell { background-color: #FFFFEE; text-align: right; font-size: 10pt; }
	.hldatacell { background-color: #FFCCCC; text-align: right; font-size: 10pt; }
	.box { border: 1px solid; padding: 10px; }
        </style>
    </head>
    <body>
        <P class="title">NCover FAQ</P>
		<p>The latest version of this document can be found <a href="http://www.ncover.com/documentation/faq">here</a>.</p>
        <P>If you have questions that this document does not address, contact <A href="mailto:support@gnoso.com">
                The Gnoso Support Team</A> or try the <A href="http://www.ncover.com/forum">NCover Forums</A>.</P>
        <P class="question">1. What is code coverage analysis?</P>
        <P class="answer">A code coverage analyzer monitors your code at runtime and 
            records information about which lines of code were executed. NCover shows each 
            sequence point in your application along with the number of times that point 
            was executed. Sequence points are generated by the compiler and stored in the 
            debug information (.pdb) files. A sequence point basically corresponds to a 
            single program statement (often a line of code) in your high-level language.</P>
        <P class="question">2. Why would I want to do code coverage analysis?</P>
        <P class="answer">Unit test suites are often used as a quality tool during the 
            development process to keep the codebase stable as it changes and expands. 
            Tools such as <A href="http://nunit.org/">NUnit</A> are often used to run and 
            report on the test suites. However, when implementing unit testing in your 
            build process, you have no way of knowing how much of your code the unit tests 
            are actually testing. This is where code coverage comes in. You can run NUnit 
            within NCover and use the code coverage report to determine which code was not 
            tested by that particular test suite.</P>
        <P class="question">3. What versions of the CLR does NCover support?</P>
        <P class="answer">
            NCover 2.0.1 requires the .NET framework version 2.0.50727 to be installed; however,
            the application being profiled can be written against any shipping version of the
            framework. NCover has been tested profiling coverage of .NET 2.0, .NET 1.1 and .NET 1.0 applications.</P>
        <P class="question">4. What is the command line syntax for NCover?</P>
        <P class="answer">Here is the usage info from the NCover command line:</P>
        <pre class="usage">Usage: ncover.console [&lt;command&gt; [&lt;command args&gt;]]
                      [//svc &lt;service name&gt;]
                      [//iis]
                      [//v] [//q]
                      [//a &lt;assembly list&gt;] [//l &lt;log file&gt;]
                      [//x &lt;xml output file&gt;]
                      [//s [&lt;settings file&gt;]] [//r [&lt;settings file&gt;]]
                      [//w &lt;working directory&gt;]

       Example command line to launch profiled application
         ncover.console myapp.exe myapp-arg1 myapp-arg2
         ncover.console //svc MyService (Enterprise Edition only)
         ncover.console //iis           (Enterprise Edition only)

       NOTE: Any command line parameters that do not start with '//'
             are passed to the profiled application on its command line.

//st   Specify the amount of time that service or IIS profiling will run before timing out
       (Enterprise Edition only)
//a    List of assemblies to profile separated by semi-colons
        i.e. "MyAssembly1;MyAssembly2"
//w    Working directory for profiled application
//ea   List of attributes marking classes or methods to exclude from coverage
//ef   List of regular expressions specifying which files to exclude from coverage
//et   List of regular expressions specifying which types to exclude from coverage
//em   List of regular expressions specifying which methods to exclude from coverage

//reg  Register profiler temporarily for user. (helps with xcopy deployment)
//ct   Specify coverage type ("SequencePoint" or "Branch") (Enterprise Edition only)
//l    Specify profiler log file
//x    Specify coverage output file
//h    Specify HTML report output path                     (Enterprise Edition only)
//p    Specify name of project for display in html output  (Enterprise Edition only)
//pm   Specify name of process to profile (i.e. myapp.exe)

//s    Save settings to a file (defaults: NCover.Settings)
//r    Use settings file, overriding other settings (default: NCover.Settings)

//q    No logging (quiet)
//v    Enable verbose logging
        </pre>
        <UL>
            <li>&lt;command line&gt; - This argument specifies the command-line of the .NET application
                you want to analyze. 
                Any command line arguments not starting with // will be passed
                through to that application. NCover will profile the running application until it has exited. See below for examples.
			</li>
			<li>//svc - This option is an alternative to the &lt;command line&gt;
                    for profiling windows services, which cannot be run directly as executables. NCover
                    will start the service (stopping it first if already running) and profile coverage
                    until the windows service is stopped. <em>Enterprise Edition Only</em>.
			</li>
            <li>//iis - This option is an alternative to the &lt;command line&gt; for profiling
                web applications. NCover will start the IISAdmin and W3C
                services (stopping first if currently running) and profile coverage until the IISAdmin
                service is stopped. <em>Enterprise Edition Only</em>.
            </li>
			<li>//st &lt;seconds&gt; - This command-line argument specifies the maximum number of seconds that
			NCover will allow a profiled windows service or IIS to run before forcing it to shutdown.
			</li>
            <li>//a - This command-line argument specifies the assemblies that you want to analyze. 
            NCover can only analyze assemblies that have .pdb files included with them. If 
            you do not specify the //a argument, NCover will attempt to analyze every loaded 
            assembly that has debug information available. Note that the assembly name arguments are
                the module name within the assembly, not the physical file name. e.g. "MyAssembly"
                rather than "MyAssembly.dll".
			</li>
			<li>//w - If the application being profiled requires the
                working directory to be set to something other than the current directory you are
                executing the command line from then you can override it with this argument.
			</li>
            <li>//ea - You can choose to exclude classes and methods
                from coverage statistics by defining .NET attribute(s) and applying it to the affected
                code. When using this argument you must specify the full type namespace of these
                attribute(s) separated by semi-colons. See below for an example.<br />
            </li>
			<li>//ef - You can exclude entire source files or groups of source files from coverage
				statistics by passing NCover regular expressions (separated by semicolons) with
				which to match the files to exclude.
			</li>
			<li>//et - You can exclude classes or groups of classes from coverage
				statistics by passing NCover regular expressions (separated by semicolons) with
				which to match the classes to exclude.
			</li>
			<li>//em - You can exclude methods or groups of methods from coverage
				statistics by passing NCover regular expressions (separated by semicolons) with
				which to match the methods to exclude.
			</li>
            <li>//reg - NCover requires a COM registration of the NCover.Lib.x86.dll (or NCover.Lib.x64.dll) assembly containing
                the profiler, which is performed automatically by the default .msi installation.
                If you require an xcopy style deployment of NCover like many other .NET tools, then
                you can use this argument which will temporarily register the profiler while performing
                coverage. This feature was added in NCover 1.5.6.
			</li>
			<li>//ct - By default, NCover performs both Sequence Point and Branch Coverage, however
			using this command you can specify one to the exclusion of the other.
			</li>
			<li>//l - The coverage log file can provide an insight if the desired coverage output
                is not obtained. Useful information you may find to assist you includes which assemblies
                were loaded by NCover, their file paths and which of those it found the .pdb build
                symbols for. Use this argument to specify an alternative log file name or location
                to coverage.log in the current directory.
			</li>
            <li>//x - The output of NCover is an xml file (example below). Use this argument to
                specify an alternate filename to "coverage.xml" in the current directory.<br />
            </li>
			<li>//h - In addition to the default xml file output, NCover can also produce a detailed
			HTML Coverage Report. Use this argument to specify the output directory of the report. <em>Enterprise Edition Only</em>.
			</li>
			<li>//p - Use this argument to specify the project name that NCover will display in the html report.
			If this option is not present, the HTML Report displays "Your Project" as the project name.
			</li>
            <li>//pm - This setting tells NCover to ignore processes that don't have the specified process module name.
            This is the name of the executable (i.e. myapp.exe).  This setting is useful in cases, where your NCover
            command spawns a series of child processes.  Using this setting will help NCover determine which process to profile.
            </li>
            <li>//s - You may find it more convenient to use a settings file rather than specifying
                a long list of command line arguments for running NCover. If you get the NCover
                command line working as you would like it and then use the //s argument it will
                save the required arguments as an xml file that can then be used by the //r argument
                below.
			</li>
            <li>//r - For use when you have used //s to construct an NCover settings file containing
                your command line arguments. e.g. "ncover.console.exe //r NCover.Settings"<br />
            </li>
            
            <li>//q - Suppresses writing the coverage.log file.</li>
            <li>//v - This command-line argument makes the profiler emit all the original IL and 
            modified IL instructions to the coverage log. This is useful for debugging 
            purposes. Beware that this can make your coverage log file very large!
            </li>
        </ul>
        <P class="question">5. Does NCover required a special compilation step for my code?</P>
        <P class="answer">No. Some code coverage tools change your source code and force 
            you to recompile it into a special build.&nbsp; NCover is designed to&nbsp;work 
            on shipping code.&nbsp; NCover uses the .NET Framework profiling API to monitor 
            your code. It does require build symbols, but can be run on release code 
            without any modifications.</P>
        <P class="question">6. How does NCover work?</P>
        <P class="answer">NCover uses the .NET Framework profiler API to monitor an 
            application's execution. When a method is loaded by the CLR, NCover retrieves 
            the IL and replaces it with instrumented IL code.&nbsp; NCover does not change 
            your original IL code, it simply inserts new code to update&nbsp;a visit 
            counter at each sequence point.&nbsp; Upon
            request, (usually after the .NET process has shut down) the profiler outputs statistics
            to the coverage file.
        </P>
        <P class="question">7. What is the output of NCover?</P>
        <P class="answer">NCover generally writes out three files after analysis 
            completes.
            <ul>
                <li>
                Coverage.log - This file is a log of the events and messages from the profiler 
                during the analysis process. Most of the time, error messages are recorded in 
                this log. If you enable verbose logging, the coverage log will contain 
                disassembly of the original and instrumented IL code.<br />
				Verbose logging is not recommended for normal use.
				</li>
				<li>
                Coverage.xml - This file is the analysis output of NCover. You can see an 
                example of the output below.
				</li>
                <LI>
                    Coverage.xsl - This file is a simple XML transformation that makes the XML 
                    output easily readable.
                </LI>
            </ul>
            <span class="subtitle">Example XML output</span>
            <div class="box">
				<pre>
&lt;method name="DoesNotBreakCoverage" signature="DoesNotBreakCoverage() : void" excluded="false" instrumented="true"&gt;
    &lt;seqpnt vc="0" l="18" el="18" c="9" ec="10" ex="true" fl="65793" doc="1" /&gt;
    &lt;seqpnt vc="1" l="19" el="19" c="13" ec="33" ex="false" fl="65536" doc="1" /&gt;
    &lt;seqpnt vc="1" l="20" el="20" c="9" ec="10" ex="false" fl="196608" doc="1" /&gt;
&lt;/method&gt;
				</pre>
            </div>
        <p></p>
        <span class="subtitle">Example transformed output</span>
        <div class="box">
            <DIV class="method">NCoverTest.ClassLoaded.HasDeadCode</DIV>
            <TABLE id="Table1" borderColor="black" cellSpacing="0" cellPadding="3" border="1">
                <TBODY>
                    <TR>
                        <TD class="hdrcell">Visit Count</TD>
                        <TD class="hdrcell">Line</TD>
                        <TD class="hdrcell">End Line</TD>
						<TD class="hdrcell">Column</TD>
                        <TD class="hdrcell">End Column</TD>
                        <TD class="hdrcell">Document</TD>
                    </TR>
                    <TR>
                        <TD class="datacell">1</TD>
                        <TD class="datacell">48</TD>
                        <TD class="datacell">48</TD>
						<TD class="datacell">13</TD>
                        <TD class="datacell">58</TD>
                        <TD class="datacell">C:\Dev\Utilities\ncover\NCoverTest\NCoverTest.cs</TD>
                    </TR>
                    <TR>
                        <TD class="datacell">1</TD>
                        <TD class="datacell">49</TD>
                        <TD class="datacell">49</TD>
						<TD class="datacell">13</TD>
                        <TD class="datacell">22</TD>
                        <TD class="datacell">C:\Dev\Utilities\ncover\NCoverTest\NCoverTest.cs</TD>
                    </TR>
                    <TR>
                        <TD class="datacell">1</TD>
                        <TD class="datacell">50</TD>
                        <TD class="datacell">50</TD>
						<TD class="datacell">17</TD>
                        <TD class="datacell">24</TD>
                        <TD class="datacell">C:\Dev\Utilities\ncover\NCoverTest\NCoverTest.cs</TD>
                    </TR>
                    <TR>
                        <TD class="hldatacell">0</TD>
                        <TD class="datacell">51</TD>
                        <TD class="datacell">51</TD>
						<TD class="datacell">13</TD>
                        <TD class="datacell">48</TD>
                        <TD class="datacell">C:\Dev\Utilities\ncover\NCoverTest\NCoverTest.cs</TD>
                    </TR>
                    <TR>
                        <TD class="hldatacell">0</TD>
                        <TD class="datacell">52</TD>
                        <TD class="datacell">52</TD>
						<TD class="datacell">9</TD>
                        <TD class="datacell">10</TD>
                        <TD class="datacell">C:\Dev\Utilities\ncover\NCoverTest\NCoverTest.cs</TD>
                    </TR>
                </TBODY>
            </TABLE>
        </div>
        <P>Suggested usages of the coverage.xml output are to display it in the <a href="http://ncoverexplorer.org/">
                NCoverExplorer</a> gui with the source
        code highlighted, to generate html reports, or to include it in your continuous build server reports such as CruiseControl.Net.
        For more information on these options see below in the FAQ.</P>
        <P></P>
        <P class="question">
            8. How do I use coverage exclusions?</P>
        <p>
            First you should define an attribute to markup your excluded code with. You will
            likely want to put this in a common assembly to make it reusable, or indeed within
            a "CommonAssemblyInfo.cs" that you include in all your application assemblies.</p>
        <P></P>
        <pre class="usage">namespace MyNamespace {
    class CoverageExcludeAttribute : System.Attribute { }
}</pre>
        <p>
            Apply the attribute to the C# classes and/or methods you wish to mark as excluded
            from code coverage statistics:</p>
        <P></P>
        <pre class="usage">    [CoverageExclude]
    private void SomeMethodToExclude() {}    </pre>
        <p>
            Finally, ensure you pass the full qualified attribute information in the NCover command line:</p>
        <P></P>
        <pre class="usage">    NCover.Console MyApplication.exe //ea MyNamespace.CoverageExcludeAttribute    </pre>
        <p>
            Note that if you are using the <a href="http://testdriven.net/">TestDriven.Net</a>
            VS.Net add-in to "Test with Coverage" it will automatically
            pass through "//ea CoverageExcludeAttribute"
            which you should define without a namespace like above. For further information refer to this
            <a href="http://weblogs.asp.net/nunitaddin/archive/2006/10/04/CoverageExclude.aspx">
                blog entry</a>.</p>
        <P class="question">9. Examples</P>
        <p>Coverage while running a simple executable until it exits:</p>
        <P></P>
        <pre class="usage">    NCover.Console MyApplication.exe</pre>
        <p>
            Coverage while running all the unit tests in an assembly using NUnit, profiling
            all loaded assemblies with .pdb build symbols:</p>
        <P></P>
        <pre class="usage">    NCover.Console nunit-console.exe MyApplication.Tests.dll</pre>
        <p>
            Coverage of only a subset of loaded assemblies while running unit tests:</p>
        <P></P>
        <pre class="usage">    NCover.Console nunit-console.exe MyApplication.Tests.dll //a MyApplication.Core;MyApplication.Utilities</pre>
        <p>
            Coverage of a windows service. Stop the service to generate the coverage output:</p>
        <P></P>
        <pre class="usage">    NCover.Console //svc MyServiceName</pre>
        <p>
            Coverage of an ASP.Net application. Stop the IIS service to generate the coverage
            output:</p>
        <P></P>
        <pre class="usage">    NCover.Console //iis</pre>
		<p>Or specify a maximum number of seconds to profile IIS before collecting coverage data: </p>
		<pre class="usage">    NCover.Console //iis //st 54</pre>
		
		<p>Use regular expressions to exclude files from coverage:</p>
		<pre class="usage">    NCover.Console myapplication.exe //ef '.*\.cpp;test.*\.cs'</pre>
		
        <P class="question">
            10. Where can I get help or support?</P>
        <P class="answer">
			The <a href="http://www.ncover.com/forum">NCover forums</a> and the original creator's
			<a href="http://www.ncover.com/blog">blog</a> answer many common questions and addresses
			many common problems. In addition, <a href="mailto:support@gnoso.com">The Gnoso Support Team</a>
			answers questions by email.
		</P>
        <P class="question">
            11. How do I "xcopy deploy" NCover like my other build tools?</P>
        <P class="answer">
            Many developers prefer to have their build tools such as NUnit, NAnt etc stored
            in source control in a Tools folder along with the source code. This ensures that
            a new developer can obtain and build the application without having to install additional
            tools on their own machines.</P>
            <p>
                NCover can also be deployed in this fashion. However, the two gotchas with NCover
                versus other tools is that the profiler within NCover.Lib.x86.dll must be COM registered
                on the local machine before you execute it, and an NCover license must be installed
				on the machine. The dll can be registered with regsvr32, or the dll can be temporarily
				registered for each run by using the //reg option. Note that the //reg option will not
				work for IIS or Windows Service profiling unless you are running NCover under the same
				Windows login account as the IIS worker process or your Windows Service. <br /><br />
				You can install an NCover license by running the registration program and following the
				prompts.
			</p>
        <P class="question">
            12. How do I see my source code highlighted with the coverage results?</P>
        <P class="answer">
			For Enterprise Edition users, NCover supports the //h command line argument which generates
			an HTML Report that supports source code highlighting, coverage summaries, and forestry conservation. <br />
			<br />
            In addition, NCoverExplorer is a gui and console-based
            .NET application, now bundled with NCover, developed by <a href="http://www.kiwidude.com/blog/">Grant Drake</a>.
			NCoverExplorer parses the coverage.xml files output from NCover and displays the results integrated
            with your source code. It also includes a number of additional features to merge,
            filter, sort and generate html reports. The console version is
            designed to be used as part of an automated build process. The support forums for
            NCoverExplorer are located with the NCover ones at <a href="http://ncover.org">http://ncover.org/</a>.<strong>&nbsp;</strong></P>
        <P class="question">
            13. How do I run NCover from within the Visual Studio.Net IDE?</P>
        <P class="answer">
            The <a href="http://testdriven.net/">TestDriven.Net</a> add-in by <a href="http://weblogs.asp.net/nunitaddin/">
                Jamie Cansdale</a> offers a right-click capability within the IDE to execute
            your unit tests with code coverage. The results of the NCover code coverage are
            displayed with the bundled NCoverExplorer gui for analysis and reporting.</P>
        <P class="question">
            14. How do I run NCover from a NAnt or MSBuild task?</P>
        <P class="answer">
            You can use an &lt;exec&gt; task with <a href="http://nant.sourceforge.net/">NAnt</a>
            or an &lt;Exec&gt; task with MSBuild. Alternatively you may want to use the custom
            &lt;ncover&gt; task for NAnt or &lt;NCover&gt; task for MSBuild developed by Grant
            Drake for a more developer friendly syntax. The documentation and compiled assemblies
            are placed within the NCover installation folder as part of the NCover installation process.
        <P class="question">
            15. How do I include NCover output in my CruiseControl.Net build reports?</P>
        <P class="answer">
            <a href="http://ccnet.thoughtworks.com/">CruiseControl.Net</a> is a continuous integration
            build server which offers web-based reporting of the outputs of a build such as
            unit test results and code coverage reporting. The default CruiseControl.Net installation
            includes a basic stylesheet which works in combination with the standard coverage.xml
            formatted output. So all you need to do is include the execution of NCover as part
            of your build, then add a CruiseControl.Net merge file publisher task to integrate
            the coverage.xml results into the build output.</P>
            <p class="answer">
                An improvement on the above to display more attractive and powerful reports as well
                as minimize the build log size is to use NCover's HTML report option. However, if
				you don't have the Enterprise edition, NCoverExplorer.Console.exe is designed to
				produce a variety of smaller reports which are combined with an
                alternate xsl stylesheet for CruiseControl.Net. You can find more information and
                screenshots in this <a href="http://www.kiwidude.com/blog/2006/04/ncoverexplorer-v133.html">
                    blog entry</a> - all the necessary tasks, examples and documentation are located
                within the NCover installation directory under the "CC.NET" folder (C:\Program Files\NCover\CC.NET) </p>
        <P class="question">
            16. How do I merge multiple NCover coverage.xml results?</P>
        <P class="answer">
            You can can use NCoverExplorer to merge the results of multiple coverage runs. For
            more information refer to this <a href="http://www.kiwidude.com/blog/2006/10/ncoverexplorer-merging-ncover-reports.html">
                blog entry</a>.</P>
        <P class="question">
             17. Troubleshooting: Why is my coverage.xml file empty?</P>
            <ul>
                <li>If using the command-line, did you COM register NCover.Lib.x86.dll (or use the //reg option
                    from NCover 1.5.6)?</li>
                <li>Did you generate build symbol files (.pdbs) for the profiled application?</li>
                <li>If using the //a option, did you correctly list just the assembly names without
                    paths or .dll suffixes?</li>
            </ul>
         <P class="question">
            18. Troubleshooting: I have coverage.xml output but my XYZ assembly is not included in it?</P>
            <ul>
                <li>NCover will only profile loaded assemblies - did your code execution path while
                    under coverage force that assembly to be loaded (e.g. by loading a type or calling
                    a method in that assembly)?&nbsp;</li>
                <li>Did you generate build symbol files (.pdb files) for the missing assembly? </li>
                <li>If using the //a option, did you correctly list the assembly names including the
                    one that is missing?</li>
                <li>Can you see information about the assembly being loaded within the coverage.log?
                    Is the correct assembly being loaded (check the path) - if you have a version in
                    the GAC it may possibly prevent the .pdb file from being loaded.</li>
				<li>If using the NCoverExplorer gui, have you got a coverage exclusion defined which
                    is hiding it from the display?</li>
            </ul>
         <P class="question">
            19. Troubleshooting: After running NCover my coverage.log says "Failed to load symbols for module XYZ"?</P>
            <ul>
                <li>This message means that no .pdb build symbol file was found for that assembly so
                    it cannot be profiled for code coverage. If that assembly is part of the .NET framework,
                    for instance System.Data.dll, then this is an expected message and should not
                    cause concern.&nbsp;</li>
				<li>If however the assembly belongs to your application, did you generate the
					build symbol files (.pdb files) for it? </li>
            </ul>
         <P class="question">
             20. Troubleshooting: My coverage exclusions are not working?</P>
            <ul>
                <li>Have you put the full namespace type name to the exclusion including the Attribute suffix in the //ea argument? See the "How
                    do I use coverage exclusions?" question above.</li></ul>
   </body>
</html>
